package com.snap.awesomeserial.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

public abstract class BaseLazyFragment extends BaseFragment {

    protected boolean isVisible;
    protected boolean isPrepared;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        isPrepared = true;
        onLazyLoad();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint()) {
            isVisible = true;
            onLazyLoad();
        } else {
            isVisible = false;
        }
    }

    protected abstract void onLazyLoad();
}
